package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.EcologyCastExpendConf;
import com.sc.nft.entity.EcologyCastWayConf;
import com.sc.nft.mapper.EcologyCastWayConfMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 生态-铸造-方式
 */
@Slf4j
@Repository
public class EcologyCastWayConfDao extends ServiceImpl<EcologyCastWayConfMapper, EcologyCastWayConf> {

    public List<EcologyCastWayConf> getListByEcologyCastConfId(Long ecologyCastConfId) {
        LambdaQueryWrapper<EcologyCastWayConf> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(EcologyCastWayConf::getEcologyCastConfId, ecologyCastConfId);
        return list(lambdaQueryWrapper);
    }

    public List<EcologyCastWayConf> getListByEcologyCastConfIdAndStatus(Long ecologyCastConfId,Boolean status) {
        LambdaQueryWrapper<EcologyCastWayConf> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(EcologyCastWayConf::getEcologyCastConfId, ecologyCastConfId);
        lambdaQueryWrapper.eq(EcologyCastWayConf::getStatus, status);
        return list(lambdaQueryWrapper);
    }

    public boolean delByEcologyCastConfId(Long ecologyCastConfId) {
        return this.lambdaUpdate()
                .eq(EcologyCastWayConf::getEcologyCastConfId, ecologyCastConfId)
                .remove();
    }

    public int countOpenByConfId(Long confId) {
        LambdaQueryWrapper<EcologyCastWayConf> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(EcologyCastWayConf::getEcologyCastConfId, confId);
        lambdaQueryWrapper.eq(EcologyCastWayConf::getStatus, Boolean.TRUE);
        return count(lambdaQueryWrapper);
    }
}